package logic

import (
	"context"
	"hema-fresh-api/hema/hema"

	"hema-fresh-api/api/internal/svc"
	"hema-fresh-api/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HemaCreateApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHemaCreateApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HemaCreateApiLogic {
	return &HemaCreateApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HemaCreateApiLogic) HemaCreateApi(req *types.HemaCreateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	create, err := l.svcCtx.HemaRpc.HemaCreate(l.ctx, &hema.HemaCreateRequest{
		Name:     req.Name,
		Image:    req.Image,
		Price:    req.Price,
		StatusId: req.StatusId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "商品添加成功",
		Code:    200,
		Data:    create,
	}, nil
}
